package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hlw.hr_man.service.AskForLeaveService;
import com.hlw.hr_man.serviceImpl.AskForLeaveServiceImpl;

/**
 * 
 * @ClassName: AgreeAflApplyController
 * @Description: 处理同意请假申请操作
 * @author 唐明
 * @date 2016年9月20日 上午9:53:10
 *
 */
public class AgreeAflApplyController extends HttpServlet{

	/**
	 * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
	 */ 
	private static final long serialVersionUID = 1L;
	
	AskForLeaveService aflService = new AskForLeaveServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//得到同意的请假记录的id
		int ask_id = Integer.parseInt(req.getParameter("ask_id"));
		//得到处理的是哪个员工的请假记录
		int e_id = Integer.parseInt(req.getParameter("e_id"));
		//处理是否成功
		int temp = aflService.agreeAflApplyByAskId(ask_id);
		PrintWriter pw = resp.getWriter();
		
		if (temp > 0) {
			//同意申请成功   将处理的记录对应的员工id存放到servlContent中，方便通知对应的员工
			String id = String.valueOf(e_id);
			req.getServletContext().setAttribute(id, e_id);
			//操作成功  返回"1"
			pw.write("1");
		} else {
			//操作失败 返回"0"
			pw.write("0");
		}
	}
}
